package eraserhead.xml.request;

import xml.Message;
import client.ServerAccess;

/**
 * Class for sending a CreateOpen request.
 * @author Michael Checca
 */
public class CreateOpenRequest {
	/**
	 * Sends a CreateOpenRequest to the server.
	 * @param sa {@link ServerAccess} to send request the {@link Message to}
	 * @param question Question of the event
	 * @param numChoices Number of choices
	 * @param numRounds Number of rounds
	 * @param moderator Username of the moderator
	 * @param password Optional password of the moderator
	 */
	public static void send(ServerAccess sa, String question, int numChoices, int numRounds, String moderator, String password) {
		String xmlMessage = String.format("%s<createRequest type=\"open\" question=\"%s\" numChoices=\"%d\" numRounds=\"%d\">",
				Message.requestHeader(), question, numChoices, numRounds) +
				String.format("<user name=\"%s\" password=\"%s\"/></createRequest></request>", moderator, password);
		sa.sendRequest(new Message(xmlMessage));
	}
}
